package com.xgp.mywordapp.service.impl;

import com.xgp.mywordapp.mapper.UserMapper;
import com.xgp.mywordapp.model.User;
import com.xgp.mywordapp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 使得总做题数+1
     * @return
     */
    @Override
    public int updateAllWord(User user) {
        user.setAllword(user.getAllword() + 1);
        int flag = userMapper.updateByPrimaryKeySelective(user);
        return flag;
    }

    /**
     * 使总刷题数+1，错题数+1
     * @return
     */
    @Override
    public int updateAllWordAndErrorWord(User user) {
        user.setAllword(user.getAllword() + 1);
        user.setErrorword(user.getErrorword() + 1);
        int flag = userMapper.updateByPrimaryKeySelective(user);
        return flag;
    }

    /**
     * 使总刷题数+1，错题数-1
     */
    @Override
    public int updateAllWordAndSubErrorWord(User user) {
        user.setAllword(user.getAllword() + 1);
        user.setErrorword(user.getErrorword() - 1);
        int flag = userMapper.updateByPrimaryKeySelective(user);
        return flag;
    }
}
